package py.edu.ucom.cadira.game.event.war;

import org.jdom.Document;
import org.jdom.Element;

import py.edu.ucom.cadira.game.war.Board;
import py.edu.ucom.cadira.game.war.WarUser;

/**
 * 
 * @author largonet
 *
 */
public class MoveTabEvent extends WarGameEvent {
    private Board table;
    private WarUser user;
    private boolean status;
    private Integer mesaId;
    public MoveTabEvent(Board table,WarUser user, boolean status, Integer mesaId) {
        this.table = table;
        this.user=user;
        this.status = status;
        this.mesaId = mesaId;
    }
    /**
     * @return the mesaId
     */
    public Integer getMesaId() {
        return mesaId;
    }
    /**
     * @param mesaId the mesaId to set
     */
    public void setMesaId(Integer mesaId) {
        this.mesaId = mesaId;
    }
    public MoveTabEvent(){
    	
    }
    public Board getTable() {
        return table;
    }
    public WarUser getUser() {
        return user;
    }
    /**
     * @return Returns the status.
     */
    public boolean isStatus() {
        return status;
    }
    /**
     * @param status The status to set.
     */
    public void setStatus(boolean status) {
        this.status = status;
    }
	@Override
	public void fromXML(Document xml) {
		Element root = xml.getRootElement();
		Element moveTabNode = root.getChild("moveFicha");
		Element statusNode = moveTabNode.getChild("status");
		setStatus(Boolean.valueOf(statusNode.getValue()));
		
		Element userNode = moveTabNode.getChild("usuario");
		user.fromXml(userNode);
		
		Element tableroNode = new Element("tablero");
		table.fromXml(tableroNode);
	}
	@Override
	public void toXML(Element root) {
		Element moveTabNode = new Element("moveTab");
		Element statusNode = new Element("status");
		statusNode.addContent(String.valueOf(status));
		moveTabNode.addContent(statusNode);
		
		Element userNode = user.toXml();
		moveTabNode.addContent(userNode);
		
		Element tableroNode = new Element("tablero");
		Element boardNode = table.toXml(tableroNode);
		tableroNode.addContent(boardNode);
		
		moveTabNode.addContent(tableroNode);
		
		root.addContent(moveTabNode);
	}
	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof MoveTabEvent)) {
			return false;
		}
		MoveTabEvent otherObj = (MoveTabEvent) obj;
		if (otherObj.getUser().equals(getUser())) {
			return true;
		}
		return false;
	}
}
